package com.jeehentor.generate.controller;

import com.jeehentor.generate.entity.SysGenPageHistory;
import com.jeehentor.generate.dto.SysGenPageHistoryDTO;
import com.jeehentor.generate.service.ISysGenPageHistoryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jeehentor.common.vo.Result;
import com.jeehentor.utils.SecurityUtil;
import org.apache.commons.lang3.StringUtils;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.core.metadata.IPage;
@Tag(name = "页面配置主表-历史记录")
@RestController
@RequestMapping("/sysGenPageHistory")
@RequiredArgsConstructor
public class SysGenPageHistoryController {

    private final ISysGenPageHistoryService sysGenPageHistoryService;

    @Operation(summary = "保存")
    @PostMapping("/save")
    public Result<String> save(@RequestBody SysGenPageHistory sysGenPageHistory){
        sysGenPageHistory.setCreateBy(SecurityUtil.getCurrentUser().getId());
        sysGenPageHistoryService.save(sysGenPageHistory);
        return Result.ok("保存成功");
    }

    @Operation(summary = "删除")
    @PostMapping("/delete")
    public Result<String> delete(@RequestBody SysGenPageHistory sysGenPageHistory){
        sysGenPageHistoryService.removeById(sysGenPageHistory);
        return Result.ok("删除成功");
    }


    @Operation(summary = "修改")
    @PostMapping("/update")
    public Result<String> update(@RequestBody SysGenPageHistory sysGenPageHistory){
        sysGenPageHistory.setUpdateBy(SecurityUtil.getCurrentUser().getId());
        sysGenPageHistoryService.updateById(sysGenPageHistory);
        return Result.ok("修改成功");
    }

    @Operation(summary = "分页查询")
    @PostMapping("/selectPage")
    public Result<IPage<SysGenPageHistory>> selectPage(@RequestBody SysGenPageHistoryDTO sysGenPageHistoryDTO){
        LambdaQueryWrapper<SysGenPageHistory> queryWrapper = new LambdaQueryWrapper<>();
        return Result.OK(sysGenPageHistoryService.page(sysGenPageHistoryDTO.getPage(),queryWrapper));
    }
}
